<?php 
class MemderController{
//	载入数据库
	private $data;
	public function __construct(){
	   	$this->data = include './data.php';
	}
//	注册
	public function reg{
		if(IS_POST){
			$this->data = array(
				'username' => $_POST['username'],
				'password' =>md5($_POST['password'])
			);
			file_put_contents('./data.php', "<?php return " .var_export($this->data,true) . "?>");
			success('注册成功', 'index.php');
		}
		include './View/reg.php';
	}
	public function login(){
	    if(IS_POST){
	    	$username = $_POST['username'];
			$password = md5($_POST['password']);
			if(strtolower($_POST['yanzheng']) != $_SESSION['thts']){
				success('验证失败', 'index.php?c=Memder&a=login');
			}
//			p($_POST);
			foreach ($this->data as $u) {
				if($u['username'] ==$username && $u['password'] ==  $password){
					$_SESSION['username'] = $username;
					if($_POST=='auto'){
						setcookie(session_name(),session_id(),time() + 3600 * 24 * 7,'/');
					}else{
						setcookie(session_name(),session_id(),0,'/');
					}
					success('登录成功', 'index.php');
				}		
			}
			success('登陆失败','index.php?c=Memder&a=login');
		}
		 include './View/login.php';
	    }
	}
	public function out(){
		session_unset();
		session_destroy();
		success('退出成功', 'index.php');
	}
}




 ?>